﻿using System.Web.Mvc;
using Orchard;
using Orchard.DisplayManagement;
using Orchard.Environment.Extensions;
using Orchard.Mvc.Filters;
using Orchard.UI.Admin;
using Orchard.UI.Navigation;

namespace SchoolPointe.Menus.Filters
{
    /// <summary>
    /// Overriding the default menu filter to suppress automatic menu shape creation in Navigation zone.
    /// Thanks http://orchardproject.net/gallery/List/Modules/Orchard.Module.Szmyd.Orchard.Modules.Menu
    /// </summary>
    [OrchardSuppressDependency("Orchard.UI.Navigation.MenuFilter")]
    public class MenuFilter : FilterProvider, IResultFilter
    {

        private readonly Orchard.UI.Navigation.MenuFilter _defaultFilter;

        public MenuFilter(INavigationManager navigationManager, IWorkContextAccessor workContextAccessor, IShapeFactory shapeFactory)
        {
            _defaultFilter = new Orchard.UI.Navigation.MenuFilter(navigationManager, workContextAccessor, shapeFactory);
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            //don't do anything unless this is in the Admin context
            if (AdminFilter.IsApplied(filterContext.RequestContext)) 
                _defaultFilter.OnResultExecuting(filterContext);
        }

        public void OnResultExecuted(ResultExecutedContext filterContext)
        {                       
            _defaultFilter.OnResultExecuted(filterContext);            
        }
    }
}